package org.example.petitionplatformsystem.service.impl;

import org.example.petitionplatformsystem.dao.ApprovalsRepository;
import org.example.petitionplatformsystem.dao.model.Approvals;
import org.example.petitionplatformsystem.service.ApprovalsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApprovalsServiceImpl implements ApprovalsService {
    @Autowired
    private ApprovalsRepository approvalsRepository;

    @Override
    public void addApproval(Approvals approval) {
        approvalsRepository.save(approval);
    }

    @Override
    public void updateApproval(Approvals approval) {
        approvalsRepository.save(approval);
    }

    @Override
    public void deleteApproval(Approvals approval) {
        approvalsRepository.delete(approval);
    }

    @Override
    public Approvals getApprovalById(long id) {
        return approvalsRepository.findById(id).orElse(null);
    }

    @Override
    public List<Approvals> getAllApprovals() {
        return approvalsRepository.findAll();
    }

    @Override
    public List<Approvals> getApproved() {
        return approvalsRepository.findApprovalsByApprovalStatus("通过");
    }
}
